﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using ww.lis.lisbll.sam;
namespace ww.form.lis.com
{
    public partial class WindowsSampleTypeForm : Form
    {
        public string strid = "";
        public string strname = "";
        SampleTypeBLL bll = new SampleTypeBLL();
        DataTable dtCurrent = new DataTable();
       
        public WindowsSampleTypeForm()
        {
            InitializeComponent();
            this.dataGridView1.AutoGenerateColumns = false;
            
        }
        private WindowsResult r;
        public WindowsSampleTypeForm(WindowsResult r)
            : this()
        {
            this.r = r;

        }

      

        private void ReturnValue()
        {
            Close();
            //try
            //{
            //    if (this.dataGridView1.Rows.Count > 0)
            //    {
            //        string strid = this.dataGridView1.CurrentRow.Cells["fsample_type_id"].Value.ToString();
            //        r.ChangeTextString(strid);
            //        this.Close();
            //    }
            //}
            //catch (Exception ex)
            //{
            //    ww.wwf.wwfbll.WWMessage.MessageShowError(ex.ToString());
            //}
        }

       
        private void ApplyUserForm_Load(object sender, EventArgs e)
        {
            GetDT();
        }

        private void GetDT()
        {
            try
            {
                this.dtCurrent = this.bll.BllDT(" WHERE (fuse_if = 1) AND (fhelp_code LIKE '" + this.textBox1.Text + "%' OR fname LIKE '" + this.textBox1.Text + "%') ");

                this.dataGridView1.DataSource = dtCurrent;
            }
            catch (Exception ex)
            {
                ww.wwf.wwfbll.WWMessage.MessageShowError(ex.ToString());
            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            GetDT();
        }
        

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            DataGridViewRow rowCurrent = this.dataGridView1.CurrentRow;
            if (rowCurrent != null)
            {
                strid = rowCurrent.Cells["fsample_type_id"].Value.ToString();
                strname = rowCurrent.Cells["fname"].Value.ToString();
                this.Close();
            }
        }

        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((e.KeyCode == Keys.Enter))
            {
                DataGridViewRow rowCurrent = this.dataGridView1.CurrentRow;
                if (rowCurrent != null)
                {
                    strid = rowCurrent.Cells["fsample_type_id"].Value.ToString();
                    strname = rowCurrent.Cells["fname"].Value.ToString();
                    this.Close();
                }
            }
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            dataGridView1_KeyDown(sender, e);
        }
    }
}